// +----------------------------------------------------------------------
// | CmsWing [ 美业管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 psi All rights reserved.
// +----------------------------------------------------------------------
// | Author: huang <2374266244@qq.com>
// +----------------------------------------------------------------------
'use strict';
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
	async indexAction(){	
		return this.display();
	}
	
	async admingrouplistAction(){
		if(this.isPost){
			//取出组数据
			let glist = await this.model('admingroup').list(this.userinfo.departmentid);
			let relist = {
				"draw": '',
				"data": glist,
				"breadcrumb":''
			}
			return this.json(relist);
		}
	}
	
	//新增组
	async addadmingroupAction(){
		if(this.isPost){
			let data = this.post();
			data.departmentid = this.userinfo.departmentid;
			let res = await this.model('admingroup').add(data);
			this.returnjson(res);
		}
	}

	//编辑组
	async editadmingroupAction(){
		if(this.isPost){
			let data = this.post();
			let res = await this.model('admingroup').update(data);
			this.returnjson(res);
		}
		let id = this.get('id');
		let ginfo = await this.model('admingroup').find(id);
		let data = {
			"ginfo":ginfo,
		}
		return this.json(data);
	}

	//删除组
	async deleteadmingroupAction(){
		let id = this.post('id');
		let res = await this.model('admingroup').delete(id);
		this.returnjson(res);
	}

	async getbrandlistAction(){
		let blist = await this.model('or_brand').where({departmentid:this.userinfo.departmentid}).select();
		return this.json(blist);
	}
}